package com.gxuwz.web.struts2;

import java.util.List;

import javax.annotation.Resource;

import com.gxuwz.annotation.LogMsg;
import com.gxuwz.entity.SysDepartment;
import com.gxuwz.entity.SysUser;
import com.gxuwz.service.IDepartmentService;
import com.gxuwz.util.DateUtils;
import com.gxuwz.util.Page;
import com.gxuwz.web.AbstractBaseController;
import com.gxuwz.web.IBaseController;

/**
 * 部门控制器
 * @author 小胡  
 * @date 2017年5月28日
 */
public class DepartmentController extends AbstractBaseController implements IBaseController{

	private static final long serialVersionUID = 6001897114947186525L;
	private SysDepartment department;
	private List<Integer> ids;	//	获取复选框的值
	
	@Resource(name = "departmentService")
	private IDepartmentService departmentService;

	/**
	 * 部门列表
	 * @return
	 */
	@Override
	public String listPrompt(){			
		Page<SysDepartment> page = new Page<SysDepartment>(); //创建分页对象指定泛型	
		page.setOnePageNum(10); //设置单页记录数 		
		page.setPageNo(pageNo==null?1:pageNo); //设置当前页数 默认1
		page.setClazz("Department");
		departmentService.findForPage(page);		
		request.put("page", page);		
		setPrompt("/WEB-INF/pages/department/department_list.jsp");
		return SUCCESS;
	}
	
	/**
	 * 跳转到增加部门的页面
	 */
	@Override
	public String addPrompt(){
		setPrompt("/WEB-INF/pages/department/department_save.jsp");
		return SUCCESS;
	}
	
	/**
	 * 新增部门信息
	 */
	@Override
	@LogMsg(msg = "新增部门")
	public String doSave(){
		SysUser user = (SysUser) session.get("user");
		department.setCreateUserName(user.getUserName());
		department.setCreateDate(DateUtils.getCurrentDate());
		departmentService.save(department);
		setPrompt("Department_listPrompt.action");
		return "reposition";
	}
	
	/**
	 * 删除部门信息
	 */
	@Override
	@LogMsg(msg = "删除部门")
	public String doBatchDelete(){
		departmentService.batchDelete(ids);
		setPrompt("Department_listPrompt.action");
		return "reposition";
	}
	
	/**
	 * 跳转到更新部门信息的页面
	 */
	@Override
	public String updatePrompt(){	
		Integer id = department.getId();
		SysDepartment dept = departmentService.load(id);
		session.put("updateDepartment", dept);
		setPrompt("/WEB-INF/pages/department/department_update.jsp");
		return SUCCESS;
	}
	
	/**
	 * 更新部门信息
	 */
	@Override
	@LogMsg(msg = "更新部门")
	public String doUpdate(){
		SysUser user = (SysUser) session.get("user");
		department.setCreateUserName(user.getUserName());
		department.setCreateDate(DateUtils.getCurrentDate());
		departmentService.update(department);
		setPrompt("Department_listPrompt.action");
		return "reposition";
	}

	
	
		
	public SysDepartment getDepartment() {
		return department;
	}

	public void setDepartment(SysDepartment department) {
		this.department = department;
	}

	public List<Integer> getIds() {
		return ids;
	}

	public void setIds(List<Integer> ids) {
		this.ids = ids;
	}	
	
}
